package vip.xiaonuo.megvii.captures.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import vip.xiaonuo.modular.megviipushdata.entity.MegviiPushData;

/**
 * 发布
 * AI主动推送数据，发布者
 */
@Service
@Slf4j
public class AiBoxActivePushDataPublisher implements ApplicationEventPublisherAware {

    // 注入事件发布者
    private ApplicationEventPublisher applicationEventPublisher;

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }

    /**
     * 发布事件
     */
    @Async
    public void pushEvent(MegviiPushData data) {
        log.info("添加推送数据给发布者: {}", data.getId());
        applicationEventPublisher.publishEvent(new AiBoxActivePushEvent(data));
    }
}

